import p from "../../../../utils/platform"
import util from '../../../../utils/util'

// component/visitorsAll/com/visitor-item/visitor-item.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    info: {
      type: Object,
      value: {}
    }
  },

  options: {
    styleIsolation: 'apply-shared',
    addGlobalClass: true,
  },

  /**
   * 组件的初始数据
   */
  data: {
    _info: {}
  },

  observers: {
    info() {
      let info = {...this.data.info }

      if (info.sign == "newHouse") {
        info.imgId = info.first_picture_url
        info.detailInfo = info.resblock_name + ' (新房)'

        this.setData({
          _info: info
        })
        return
      }


      if (info.buildingNum || info.unit == '' || info.roomNo) {
        var kong = '未填户型'
      } else {
        kong = `${info.buildingNum ? info.buildingNum + '栋-' : ''}
        ${info.unit ? info.unit + '单元' + '' : '无单元'}
        ${info.roomNo ? '-' + info.roomNo + '室' : ''}`
      }
      info.detailInfo = `
        ${info.title?info.title:''}
        ${info.build_size && info.build_size!=-1?info.build_size + '平':'未填面积'}
        ${info.total_prices && info.total_prices!=-1? '总价' + (info.total_prices>=10000 ? info.total_prices/10000 + '万' : info.total_prices + '元'):'未填价格'}
      `
      this.setData({
        _info: info
      })
    }
  },
  attached() {
    const that = this;
    that.setData({
      url: util.ImagesUrl
    })
  },
  /**
   * 组件的方法列表
   */
  methods: {
    handleGoRentalHouseDetail() {
      if (this.data.info.deleted) {
        wx.showToast({
          icon: 'none',
          title: '该房源被删除，无法查看',
        })
        return
      }
      
      if (this.data.info.isOtherPeopleHose) {
        p.showModal({
          content: '这是用户访问的其他经纪人房源，暂时不支持访问',
          showCancel: false
        })
        return
      }

      if (this.data.info.sign == "newHouse") {
        wx.navigateTo({
          url: `/pages/newBuildinghouse/newRentalHouseDetail/newRentalHouseDetail?houdelid=${this.data.info.id}&isMay=true`
        })

        return
      }


      // console.log(this.data.info);
      const houdelid = this.data.info.houDelId;
      const houseTypes = this.data.info.housetype;
      wx.navigateTo({
        url: '/pages/house/RentalHouseDetail/RentalHouseDetail?houdelid=' + houdelid + "&from=1" + "&type=" + houseTypes,
      })
    },
  }
})